package com.tianhui.consignortwofei.mvp.ui.fragment;

import android.view.View;
import android.widget.FrameLayout;

import com.fgs.common.CommonFragment;
import com.fgs.common.CommonPresenter;
import com.fgs.common.CommonView;
import com.fgs.common.adapter.FragmentPagerAdapter;
import com.fgs.common.other.CommonEvent;
import com.fgs.common.widget.CustomViewPager;
import com.flyco.tablayout.SlidingTabLayout;
import com.flyco.tablayout.listener.OnTabSelectListener;
import com.tianhui.consignortwofei.R;
import com.tianhui.consignortwofei.base.BaseFragment;
import com.tianhui.consignortwofei.other.EventWhat;
import com.tianhui.consignortwofei.pattern.orderStatus.status.impl.DaFuDispatchStatus;
import com.tianhui.consignortwofei.pattern.orderStatus.status.impl.FreightStatus;

import java.util.ArrayList;
import java.util.Arrays;
import java.util.List;

import butterknife.BindView;


/**
 * @author fgs
 * @date 2020/9/9
 * @description
 **/
public class WaybillFragmentTwo extends BaseFragment {

    @BindView(R.id.activity_order_list_viewPager)
    CustomViewPager mViewPager;
    @BindView(R.id.activity_order_list_slidingTabLayout)
    SlidingTabLayout mTabLayout;
    @BindView(R.id.activity_order_list_TabFrameLayout)
    FrameLayout mTabFrameLayout;
    private List<CommonFragment> mFragmentList = new ArrayList<>();
    private FragmentPagerAdapter mPagerAdapter;

    public WaybillFragmentTwo() {
        // Required empty public constructor
    }

    @Override
    protected int getLayoutId() {
        return R.layout.activity_order_list;
    }

    @Override
    protected CommonView createView() {
        return null;
    }

    @Override
    protected CommonPresenter createPresenter() {
        return null;
    }

    @Override
    protected void init() {


        mPagerAdapter = new FragmentPagerAdapter(getFragmentManager());
        mPagerAdapter.setFragments(createFragmentList());
        mViewPager.setCanScroll(false);
        mViewPager.setHasEffect(false);
        mViewPager.setOffscreenPageLimit(mFragmentList.size());
        mViewPager.setAdapter(mPagerAdapter);

        mPagerAdapter.setTabTitles(Arrays.asList(getResources().getStringArray(R.array.array_yuadan_tab_two)));
        mTabLayout.setViewPager(mViewPager);


//        Bundle bundle = getIntent().getExtras();
        int index = 0;
//        if (bundle != null && !bundle.isEmpty()) {
//            index = bundle.getInt(KeyValue.KEY_TYPE);
//            if (index == OrderType.TYPE_SOURCE) {
        setCurrentItem(0);
//                getToolbarStatus().setTitle("货源管理");
//            }
////            else if (index == OrderType.TYPE_INQUIRY) {
////                setCurrentItem(1);
////                getToolbarStatus().setTitle("询价管理");
////            }
//            else if (index == OrderType.TYPE_DISPATCH) {
//                setCurrentItem(1);
//        getToolbarStatus().setTitle("调度管理");
//            }
//        }







//        boolean isShowOrderTypeTabLayout = RoleController.getInstance().isShowOrderTypeTabLayout();
//        if (isShowOrderTypeTabLayout) {
            mTabFrameLayout.setVisibility(View.VISIBLE);
//        } else {
//            mTabFrameLayout.setVisibility(View.GONE);
//        }


        initListener();
    }



    private void initListener() {

        mTabLayout.setOnTabSelectListener(new OnTabSelectListener() {
            @Override
            public void onTabSelect(int position) {
                switch (position) {
                    case 0:
                        mViewPager.setCurrentItem(0);
//                        getToolbarStatus().setTitle("货源管理");

                        break;
//                    case 1:
//                        mViewPager.setCurrentItem(1);
//                        getToolbarStatus().setTitle("询价管理");
//                        break;
                    case 1:
                        mViewPager.setCurrentItem(1);
//                        getToolbarStatus().setTitle("调度管理");
                        break;
                    case 2:
                        mViewPager.setCurrentItem(2);
//                        getToolbarStatus().setTitle("调度管理");
                        break;
//                    case 3:
//                        mViewPager.setCurrentItem(3);
////                        getToolbarStatus().setTitle("调度管理");
//                        break;
//                    case 4:
//                        mViewPager.setCurrentItem(4);
////                        getToolbarStatus().setTitle("调度管理");
//                        break;
//                    case 5:
//                        mViewPager.setCurrentItem(5);
////                        getToolbarStatus().setTitle("调度管理");
//                        break;
//                    case 6:
//                        mViewPager.setCurrentItem(6);
////                        getToolbarStatus().setTitle("调度管理");
//                        break;


                }
            }

            @Override
            public void onTabReselect(int position) {

            }
        });

    }

    private List<CommonFragment> createFragmentList() {
//        mFragmentList.add(OrderListFragment.newInstance(new SourceStatus()));//货源
//        mFragmentList.add(OrderListFragment.newInstance(new InquirySourceStatus()));

//        mFragmentList.add(ToExamineListFragment.newInstance(new ToExamineStatus()));//审核单new

//1:未抢单,2:已取消,3:待装货,4:取消确认中,5:确认装车,6:确认收货,7:运输中,9:待收款,10:作废,11:终止,12:已计算,13付款中,14:已完成
//1,3,7,9,14,4
//        mFragmentList.add(OrderListFragment.newInstance(new SourceStatus()));//货源
//        mFragmentList.add(SourceDocumentListFragment.newInstance(new SourceStatus()));//货源new

//        mFragmentList.add(DispatchListFragment.newInstance(new YiQiangDispatchStatus()));//已抢单
//        mFragmentList.add(InTransitListFragment.newInstance(new YiQiangDispatchStatus()));//已抢单new
//        mFragmentList.add(DispatchListFragment.newInstance(new YunShuDispatchStatus()));//运输中
//        mFragmentList.add(InTransitListFragment.newInstance(new YunShuDispatchStatus()));//运输中new
//        mFragmentList.add(DispatchListFragment.newInstance(new DaFuDispatchStatus()));//待收款
        mFragmentList.add(InTransitListFragment.newInstance(new DaFuDispatchStatus()));//待收款new



//        mFragmentList.add(OrderListFragment.newInstance(new SourceStatusDingJin()));//有定金
//        mFragmentList.add(OrderListFragment.newInstance(new DispatchStatus()));//调度
//        mFragmentList.add(OrderListFragment.newInstance(new DispatchStatusDingJin()));//有定金

//        mFragmentList.add(OrderListFragment.newInstance(new FreightStatus()).setIsNeedLazyLoad(false).setSearchKey(""));//运费计算
        mFragmentList.add(FreightPayListFragment.newInstance(new FreightStatus()).setIsNeedLazyLoad(false).setSearchKey(""));//运费计算new
//        mFragmentList.add(OrderListFragment.newInstance(new PaymentStatus()).setIsNeedLazyLoad(false).setSearchKey(""));//付款申请
//        mFragmentList.add(FreightPayListFragment.newInstance(new PaymentStatus()).setIsNeedLazyLoad(false).setSearchKey(""));//付款申请new


//        mFragmentList.add(DispatchListFragment.newInstance(new WanChengDispatchStatus()));//已完成
//        mFragmentList.add(InTransitListFragment.newInstance(new WanChengDispatchStatus()));//已完成new
//        mFragmentList.add(DispatchListFragment.newInstance(new QuXiaoDispatchStatus()));//取消中
//        mFragmentList.add(InTransitListFragment.newInstance(new QuXiaoDispatchStatus()));//取消中new

        return mFragmentList;
    }

    private void setCurrentItem(int item) {
        mViewPager.setCurrentItem(item);
    }



    @Override
    public void onEvent(CommonEvent event) {
        super.onEvent(event);
        switch (EventWhat.valueOf(event.getWhat())) {
            case EVENT_MOVE_TO_JISUAN:
                mTabLayout.setCurrentTab(5);
                break;


        }
    }


}
